package com.liu.vod.controller;

import com.liu.commonutils.ReturnResult;
import com.liu.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/eduvod/video")
public class VodController {

    @Autowired
    private VodService vodService;

    //上传视频到阿里云
    @PostMapping("/uploadAliyunVideo")
    public ReturnResult uploadAliyunVideo(MultipartFile file){
        //返回上传视频的id
        String videoId = vodService.uploadVideoAliyun(file);
        return ReturnResult.ok().data("videoId",videoId);
    }

    // 根据视频id删除阿里云视频
    @DeleteMapping("/removeAliyunVideoById/{id}")
    public ReturnResult removeAliyunVideoById(@PathVariable String id){
        vodService.removeAliyunVideoById(id);
        return ReturnResult.ok();
    }


    // 传递几个视频id就需要删除对少个阿里云视频(批量删除视频)
    @DeleteMapping("/removeBatch")
    public ReturnResult removeBatch(@RequestParam("videoIdList") List<String> videoIdList){
        vodService.removeMoreVideo(videoIdList);
        return ReturnResult.ok();
    }
}
